package java_thinking.unit_19._19_7_9;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;

/**
 * @Desc:
 * @author: cww
 * @DateTime: 2019/5/23 9:04
 */
enum CharacterCategory {
    VOWEL('a', 'e', 'i', 'o', 'u') {
        public String toString() {
            return "vowel";
        }
    },
    SOMETIMES_A_VOWEL('y', 'w') {
        public String toString() {
            return "sometimes a vowel";
        }
    },
    CONSONANT {
        public String toString() { return "consonant"; }
    };
    private HashSet<Character> chars = new HashSet<>();

    /**
     * 可变参数适应多种枚举实例
     * @param chars
     */
    private CharacterCategory(Character... chars) {
        if (chars != null) {
            this.chars.addAll(Arrays.asList(chars));
        }
    }
    public static CharacterCategory getCategory(Character c) {
        if ((VOWEL.chars.contains(c))) {
            return VOWEL;
        }
        if (SOMETIMES_A_VOWEL.chars.contains(c)) {
            return SOMETIMES_A_VOWEL;
        }
        return CONSONANT;
    }

}
public class E05_VowelsAndConsonants2 {
    public static void main(String[] args) {
        Random rand = new Random(47);
        for (int i = 0; i < 100; i++) {
            int c = rand.nextInt(26) + 'a';
            System.out.println((char)c + ", " + c + ": ");
            System.out.print(CharacterCategory.getCategory((char)c).toString());
        }
    }
}
